<template>
    <div class="container">
        <header>
            <div class="headlie-title">
                订单列表
            </div>
        </header>
        <div v-for="(order,index) in orders" :key="index">
            <div class="order">
                <div class="order-header">
                    <div class="time">
                        {{order.time_end}}
                    </div>
                    <div class="state">
                        {{order.status}}
                    </div>
            </div>
        <div class="order-foods" :data="order">
            <div v-for="(food,index) in order.menus" :key="index">
                <div class="food">
                    <img class="img" :src="'http://47.104.186.142:8000/'+food.pic_url">
                    <div class="content">
                    <h3 class="title">{{food.name}}</h3>
                    <div class="describe">{{food.remark}}</div>
                    <div class="price-number">
                        <div class="price">
                            ￥{{food.price}}
                        </div>
                        <div class="number">
                            X{{food.amount}}
                        </div>
                    </div>
                </div>
            </div>
            <div class="payment-amount">
                <span class="discount"> 优惠金额：￥ 0.00 </span>
                <span class="amount-paid"> 实付金额： ￥ {{order.total_fee/100}} </span>
            </div>
           </div>
        </div>
        <div class="operate-content">
            <button class="white" type="button" @click="gotoDetail(order.order_num)">订单详情</button>
        </div>
        </div>
    </div>

       <!-- 若无订单则显示此div -->
       <div class="no-data" v-show="showNodata">
          <img class="img" src="../../commom/image/nodata.png" />
          <p class="text">暂无订单</p>
       </div>
    </div>
</template>

<script type="text/ecamscript-6">
import order from "@/components/order/order";
export default {
  data() {
    return {
      orders: [],
      userId: "",
      showNodata: false
    };
  },
  components: {
    order
  },
  created() {
    // 用户从微信环境打开首页面，链接后携带ucode参数
    // console.log(this.$route.query.ucode);
    let u_code_temp = this.$route.query.ucode;
    let _this = this;

    // 请求Ucode接口
    this.$axios({
      method: "get",
      url: "http://47.104.186.142:80/code/ucode",
      params: {
        ucode: u_code_temp
      }
    }).then(res => {
      if (res.data.code == 0) {
        sessionStorage.setItem("setUserId", res.data.data.uid);
        // 从后台获取订单信息【订单查询接口】
        this.$axios({
          method: "get",
          url: "http://47.104.186.142:80/order/queryOrder",
          params: {
            user_id: res.data.data.uid
          }
        }).then(res => {
          _this.orders = res.data.data;
          if (res.data.data.length == 0) {
            _this.showNodata = true;
          }
        });
      } else {
        // ucode不正确,跳转微信授权登陆
        window.location.href ="http://tanqin520.udutech.com/login?state=myorder";
      }
    });
  },
  methods: {
    gotoDetail(order_num) {
      this.$router.push({
        path: `/orderDetail`
      });
      sessionStorage.setItem("setOrderNum", order_num);
    }
  }
};
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
@import '~commom/stylus/mixin';

.container {
    background-color: #f0f0f0;
    overflow: hidden;
    padding-top: 44px;
    min-height: 100vh;

    header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 44px;
        background-color: #f20c00;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 15px;
        text-align: center;
        color: #fff;
    }

    .headlie-title {
        width: 80px;
        margin: 0 auto;
    }

    .order {
        margin: 0 0 10px;
        background-color: #ffffff;
    }
}

.order {
    padding: 0 15px;

    .order-header {
        height: 45px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 14px;

        .time {
            color: #333333;
        }

        .state {
            color: #f20c00;
        }
    }

    .order-foods {
        .food {
            padding: 10px 0;
            border-top: 1px solid #eeeeee;
            display: flex;

            .img {
                flex: 0 0 105px;
                width: 105px;
                height: 70px;
                margin-right: 15px;
            }

            .content {
                flex: 1;

                .title {
                    color: #333;
                    font-size: 15px;
                    font-weight: bold;
                }

                .describe {
                    color: #666;
                    font-size: 13px;
                    line-height: 16px;
                    height: 32px;
                    line-hidden(2);
                    margin: 5px 0;
                }

                .price-number {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    .price {
                        color: #f20c00;
                        font-size: 12px;
                    }

                    .number {
                        font-size: 13px;
                        color: #333333;
                    }
                }
            }
        }
    }

    .payment-amount {
        overflow: hidden;
        height: 45px;
        border-bottom: 1px solid #eeeeee;
        border-top: 1px solid #eeeeee;
        line-height: 45px;
        color: #333333;
        font-size: 13px;

        .discount {
            margin-right: 30px;
        }
    }

    .operate-content {
        display: flex;
        justify-content: flex-end;
        padding: 10px 0;

        button {
            height: 30px;
            width: 91px;
            text-align: center;
            border: none;
            outline: none;
            border-radius: 20px;
            font-size: 13px;

            &.red {
                background-color: #f20c00;
                color: #ffffff;
            }

            &.white {
                margin-left: 16px;
                background-color: #ffffff;
                border: 1px solid #333333;
                color: #333333;
            }
        }
    }
}

.no-data {
    margin: 0 auto;
    max-width: 90%;
    padding: 40px 0;
}

.img {
    margin: 0 auto;
    display: block;
    max-width: 100%;
}

.text {
    text-align: center;
    font-size: 18px;
    color: #666;
    padding: 20px 20px 0 0;
}
</style>